#include "../include/FireworkCircles.h"

#include <algorithm>
#include <iterator>

#include "../include/utilities.h"

void FireworkCircles::initFireworkParticles() {
	std::normal_distribution<float> speedDis(5, 0.5);
	std::uniform_real_distribution<float> radiusDis(-20, 20);
	std::uniform_int_distribution pointCountDis(-20, 20);
	
	float radius = 100 + radiusDis(m_gen);
	Vector3 normal = getRandomNormal(-90, 90, 0, 360);
	float initSpeed = fabsf(speedDis(m_gen));
	float lengthBomb = 2;
	std::vector<Vector3> circlePointPos = getNormalCirclePos(m_pos, radius, normal, 0, 360, 10 + pointCountDis(m_gen));
	std::vector<Vector3> speedList = getSpeedlistFromPoslist(m_pos, initSpeed, circlePointPos);
	
	float speedRatio = 1.3;
	float iterRatio = 0.1;
	std::uniform_int_distribution pointNewCountDis(-10, 10);
	float iterCount = 0;
	while (isToDo(iterRatio) || iterCount < 4) {
		iterCount++;
		//		color = getRandomColor();
		initSpeed *= speedRatio;
		std::vector<Vector3> circlePointPos = getNormalCirclePos(m_pos, radius, normal, 0, 360, 20 + pointNewCountDis(m_gen) + (int)iterCount * 10);
		std::vector<Vector3> tmpSpeedList = getSpeedlistFromPoslist(m_pos, initSpeed, circlePointPos);
		//		addNewBombs(pos, speedList, color, lengthBomb);
		std::copy_n(tmpSpeedList.begin(), tmpSpeedList.size(), std::back_inserter(speedList));
		
		if (iterCount > 8) break;
	}
	Color color = getRandomColor();
	addNewBombs(m_pos, speedList, color, lengthBomb);
}
